package dev.kaayf.db;

import static android.content.Context.MODE_PRIVATE;

import android.content.Context;
import android.content.SharedPreferences;

public class UserPrefs {
    private Context context;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor prefs;

    public static final String PREFS_NAME = "kaayf_note";
    public static final String USER_NAME = "user";
    public static final String FIRST_LAUNCH = "launch";


    public UserPrefs(Context context) {
        this.context = context;
        sharedPreferences = context.getSharedPreferences(PREFS_NAME,MODE_PRIVATE);
        prefs = sharedPreferences.edit();
    }

    // if first time to launch,return true else false
    public boolean isFirstLaunch(){
        return sharedPreferences.getBoolean(FIRST_LAUNCH, true);
    }

    public void setUserName(String name){
        prefs.putString(USER_NAME, name);
        prefs.commit();
    }

    // get user name from prefs
    public String getUserName(){
        return sharedPreferences.getString(USER_NAME,"User");
    }

    // set first time launch flag to false
    public void setFirstLaunch(){
        prefs.putBoolean(FIRST_LAUNCH,false);
        prefs.commit();
    }

}
